package org.come.mouslisten;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;

import javax.swing.ImageIcon;

import org.come.Frame.CollectionJadeJframe;
import org.come.Frame.ExchangeValueJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.CollectionJadeJpanel;
import org.come.Jpanel.ExchangeValueJpanel;
import org.come.Jpanel.JadeUpJpanel;
import org.come.Jpanel.StorageJadeJpanel;
import org.come.Jpanel.StorageJadeJpanel2;
import org.come.Jpanel.StorageJadeJpanel3;
import org.come.Jpanel.StorageJadeJpanel4;
import org.come.Jpanel.SynthesisJpanel;
import org.come.entity.Goodstable;
import org.come.until.AccessSuitMsgUntil;

public class StorageJadeMouslisten implements MouseListener {

	private int index;// 哪一个位置的玉符
	private int type;// 哪一个面板 1：兑换灵修值 2：收录玉符 3：套装合成 4： 玉符升级
	private String skin; // 玉符的皮肤
	private int[] jadeNum = new int[5]; // 存放玉符的数量

	public StorageJadeMouslisten(int index, int type) {
		this.index = index;
		this.type = type;
		skin = "tzyf" + (index + 1); // 玉符的皮肤
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getButton() == MouseEvent.BUTTON3) {// 右键点击
			if (type == 1) {// 兑换灵修值
				if (StorageJadeJpanel.partJade != null) {
					jadeNum[0] = StorageJadeJpanel.partJade.getJade1();
					jadeNum[1] = StorageJadeJpanel.partJade.getJade2();
					jadeNum[2] = StorageJadeJpanel.partJade.getJade3();
					jadeNum[3] = StorageJadeJpanel.partJade.getJade4();
					jadeNum[4] = StorageJadeJpanel.partJade.getJade5();

					if (jadeNum[index] > 0) {// 表示有玉符
						// 展示面板信息
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getLabTzyf()
								.setIcon(new ImageIcon(new ImageIcon("img/item/" + skin + ".png").getImage().getScaledInstance(54, 51, 10)));
						// 默认兑换数量是一
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getTextNum().setText("1");
						// 可以兑换的灵修值
						ExchangeValueJpanel.khdlxz = new BigDecimal(AccessSuitMsgUntil.returnExcNum((index + 1)));
						// 存放要兑换的玉符
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getJadeorGoodstableBean().setType((index + 1));
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getJadeorGoodstableBean().setGoodstable(null);
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getJadeorGoodstableBean()
								.setPartJade(StorageJadeJpanel.partJade);
					} else {
						// 展示面板信息
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getLabTzyf().setIcon(null);
						// 默认兑换数量是一
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getTextNum().setText("");
						// 可以兑换的灵修值
						ExchangeValueJpanel.khdlxz = null;
						// 存放要兑换的玉符
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getJadeorGoodstableBean().setType(0);
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getJadeorGoodstableBean().setGoodstable(null);
						ExchangeValueJframe.getExchangeValueJframe().getValueJpanel().getJadeorGoodstableBean().setPartJade(null);
					}
				}
			} else if (type == 2) {// 收录玉符
				if (StorageJadeJpanel2.partJade != null) {
					jadeNum[0] = StorageJadeJpanel2.partJade.getJade1();
					jadeNum[1] = StorageJadeJpanel2.partJade.getJade2();
					jadeNum[2] = StorageJadeJpanel2.partJade.getJade3();
					jadeNum[3] = StorageJadeJpanel2.partJade.getJade4();
					jadeNum[4] = StorageJadeJpanel2.partJade.getJade5();

					if (jadeNum[index] > 0) {// 表示有玉符
						// 展示面板信息
						CollectionJadeJframe.getCollectionJadeJframe().getJadeJpanel().getLabTzyf()
								.setIcon(new ImageIcon(new ImageIcon("img/item/" + skin + ".png").getImage().getScaledInstance(54, 51, 10)));
						// 这个套装所收录的部件数量
						int num = AccessSuitMsgUntil.getCollNum(StorageJadeJpanel2.partJade.getSuitid());
						// 所需灵修值
						CollectionJadeJpanel.sxlxz = new BigDecimal(50);
						// 所需金钱
						CollectionJadeJpanel.money = new BigDecimal((num + 1) * 10000000);
						// 存放要兑换的玉符
						CollectionJadeJframe.getCollectionJadeJframe().getJadeJpanel().getGoodstableBean().setType((index + 1));
						CollectionJadeJframe.getCollectionJadeJframe().getJadeJpanel().getGoodstableBean()
								.setPartJade(StorageJadeJpanel2.partJade);

					} else {
						CollectionJadeJframe.getCollectionJadeJframe().getJadeJpanel().getLabTzyf().setIcon(null);
						CollectionJadeJpanel.money = null;
						CollectionJadeJpanel.sxlxz = null;
						CollectionJadeJframe.getCollectionJadeJframe().getJadeJpanel().getGoodstableBean().setType(0);
						CollectionJadeJframe.getCollectionJadeJframe().getJadeJpanel().getGoodstableBean().setPartJade(null);
					}
				}
			} else if (type == 3) {// 套装合成
				if (StorageJadeJpanel3.partJade != null) {
					jadeNum[0] = StorageJadeJpanel3.partJade.getJade1();
					jadeNum[1] = StorageJadeJpanel3.partJade.getJade2();
					jadeNum[2] = StorageJadeJpanel3.partJade.getJade3();
					jadeNum[3] = StorageJadeJpanel3.partJade.getJade4();
					jadeNum[4] = StorageJadeJpanel3.partJade.getJade5();

					if (jadeNum[index] > 0) {// 表示有玉符
						// 获取要合成的玉符
						SynthesisJpanel.getGoodstableBean().setPartJade(StorageJadeJpanel3.partJade);
						SynthesisJpanel.getGoodstableBean().setType((index + 1));
						// 展示玉符的照片
						SynthesisJpanel.getLabyf()
								.setIcon(
										new ImageIcon(new ImageIcon("img/item/tzyf" + (index + 1) + ".png").getImage().getScaledInstance(53,
												51, 10)));
						BigDecimal big = AccessSuitMsgUntil.returnMoney(SynthesisJpanel.getGoodstableBean(), 1);
						if (big != null) {// 消耗的金钱
							SynthesisJpanel.setMoney(big);
						}
					}
				}
			} else if (type == 4) {// 玉符升级
				if (StorageJadeJpanel4.partJade != null) {
					jadeNum[0] = StorageJadeJpanel4.partJade.getJade1();
					jadeNum[1] = StorageJadeJpanel4.partJade.getJade2();
					jadeNum[2] = StorageJadeJpanel4.partJade.getJade3();
					jadeNum[3] = StorageJadeJpanel4.partJade.getJade4();
					jadeNum[4] = StorageJadeJpanel4.partJade.getJade5();

					if (jadeNum[index] > 0) {// 表示有玉符
						// 展示玉符的照片
						JadeUpJpanel.getLabyf()
								.setIcon(
										new ImageIcon(new ImageIcon("img/item/tzyf" + (index + 1) + ".png").getImage().getScaledInstance(54,
												51, 10)));
						JadeUpJpanel.getLabpz().setText(AccessSuitMsgUntil.returnJadeName((index + 1)));
						JadeUpJpanel.getLabgs().setText(jadeNum[index] + "");
						if (AccessSuitMsgUntil.returnJadeMoney((index + 1)) != null) {
							JadeUpJpanel.setMoney(AccessSuitMsgUntil.returnJadeMoney((index + 1)));
						}
						int num = AccessSuitMsgUntil.returnJadeNum((index + 1));
						if (num != 0) {
							JadeUpJpanel.setNumber((jadeNum[index] - num) >= 0 ? 0 : (num - jadeNum[index]));// 还需要几个玉符
							JadeUpJpanel.getGoodstableBean().setPartJade(StorageJadeJpanel4.partJade);
							JadeUpJpanel.getGoodstableBean().setType((index + 1));
						} else {
							JadeUpJpanel.setNumber(-1);
						}
					}
				}
			}
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		showMsg(index);
	}

	@Override
	public void mouseExited(MouseEvent e) {
		ZhuFrame.getZhuJpanel().cleargoodtext();
	}

	public static void showMsg(int index) {
		String instruction = "";
		if (index == 0) {
			instruction = "灵宝天尊炼制的玉符，可辟邪，可祛病，可祈福，可令装备产生玄妙的变化。        品质：把玩";
		} else if (index == 1) {
			instruction = "灵宝天尊炼制的玉符，可辟邪，可祛病，可祈福，可令装备产生玄妙的变化。        品质：贴身";
		} else if (index == 2) {
			instruction = "灵宝天尊炼制的玉符，可辟邪，可祛病，可祈福，可令装备产生玄妙的变化。        品质：珍藏";
		} else if (index == 3) {
			instruction = "灵宝天尊炼制的玉符，可辟邪，可祛病，可祈福，可令装备产生玄妙的变化。        品质：无价";
		} else if (index == 4) {
			instruction = "灵宝天尊炼制的玉符，可辟邪，可祛病，可祈福，可令装备产生玄妙的变化。        品质：传世";
		}
		Goodstable goodstable = new Goodstable();
        goodstable.setSkin("tzyf" + (index + 1));
        goodstable.setGoodsname("灵宝玉符"); 
        goodstable.setInstruction(instruction); 
        goodstable.setValue(""); 
        goodstable.setQuality(1L);
		ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
	}
}
